package com.btnc.bpm.cbr;

import static org.apache.camel.builder.xml.XPathBuilder.xpath;

import javax.xml.transform.dom.DOMSource;

import org.apache.camel.builder.RouteBuilder;

public class RequestDSLRouter extends RouteBuilder {
	private final static String JBI_SERVICE = "jbi:service:";
	private final static String NAMESPACE = "http://btnc.com/bpm";
	private final static String SERVICE_IN = JBI_SERVICE + NAMESPACE
			+ "/requestDSLRouter";
	private final static String BTNC_REQUEST_OUT = JBI_SERVICE + NAMESPACE
			+ "/btncRequest";
	private final static String TRAFFY_REQUEST_OUT = JBI_SERVICE + NAMESPACE
			+ "/traffyRequest";
	private final static String GOOGLE_REQUEST_OUT = JBI_SERVICE + NAMESPACE
			+ "/googleRequest";
	private final static String FAILURE_OUT = JBI_SERVICE + NAMESPACE
			+ "/failureRequest";

	@Override
	public void configure() throws Exception {
		errorHandler(deadLetterChannel(FAILURE_OUT).maximumRedeliveries(2)
				.redeliverDelay(5000));
		from(SERVICE_IN).convertBodyTo(DOMSource.class).choice()
				.when(xpath("/btnc")).to(BTNC_REQUEST_OUT)
				.when(xpath("/traffy")).to(TRAFFY_REQUEST_OUT)
				.when(xpath("/google")).to(GOOGLE_REQUEST_OUT).otherwise()
				.to(FAILURE_OUT);

	}

}
